Skip to content

fix(python-uv): don't reinstall pruned packages - #979

Open
bnusunny wants to merge 1 commit into
aws:developfrom
bnusunny:fix/python-uv-prune-no-deps
Open

bnusunny wants to merge 1 commit into
aws:developfrom
bnusunny:fix/python-uv-prune-no-deps

Conversation

@bnusunny

Copy link
Copy Markdown
Contributor

Issue #, if available: Follow-up to #966

Description of changes

uv_prune (SAM CLI UvPrune) didn't remove a package that another kept package depends on. uv export --prune botocore leaves botocore out of the exported requirements, but the next step, uv pip install -r <export>, resolved dependencies again and installed botocore and its dependencies anyway. On Lambda the bundled copy then shadows the runtime's.

The export is already the full locked set, so the lock path now installs it with --no-deps. install_requirements() gets a no_deps option, and only _build_from_lock_file() sets it, which covers pyproject.toml builds with or without uv.lock. requirements.txt builds still resolve dependencies. DESIGN.md is updated.

The existing prune test prunes boto3, a direct dependency that nothing else requires, so it passed before this fix. The new integration test prunes botocore under aws-xray-sdk.

Description of how you validated changes

  • New integration test test_workflow_prunes_transitive_dependency_of_kept_package fails on develop (botocore 1.44.7 installed) and passes with the fix. New unit tests check --no-deps is passed only on the lock path.
  • make lint and make black-check pass. pytest tests/unit passes (1078), and tests/integration/workflows/python_uv passes with uv 0.13.9 (74).
  • Workspace members and path dependencies: the export lists their dependencies, so the installed set is unchanged with --no-deps.
  • End to end with SAM CLI develop and this branch, a python3.13 arm64 function with UvPrune: [botocore] deployed to Lambda now loads botocore from the runtime instead of /var/task, and the build drops from 30 MB to 2.3 MB. requirements.txt, UvCompileBytecode and layer builds produce the same output as before.

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

The lock build installs the `uv export` output with `uv pip install -r`, which
resolved dependencies again. A package removed with uv_prune came back when a
kept package depends on it (e.g. pruning botocore under aws-xray-sdk), along
with its own dependencies.

The export is already the full locked closure, so install it with --no-deps.
Plain requirements.txt builds still resolve dependencies.
@bnusunny
bnusunny requested a review from a team as a code owner November 20, 2026 16:42
@bnusunny
bnusunny requested review from licjun and vicheey November 20, 2026 16:43
@aws-sam-tooling-bot

Copy link
Copy Markdown

🧪 Hands-on test: No problems observed in 7 scenarios

Commit 7de59e1 · build LambdaToolingHandsOn-NoDocker:c2ebc84d-05d2-4127-97bd-9693808fd63b. The plan's scenarios ran on an isolated build host; a problem is reported only if it reproduced at least twice. Passing scenarios show only that these checks behaved as expected, not that the change is correct.

Scenarios

Scenario Planned check Result Runner's note
S1 Main fix: with an existing uv.lock, pruning botocore (a dependency of the kept aws-xray-sdk) must keep botocore and the… ✅ pass Existing uv.lock, uv_prune [botocore], aws-xray-sdk==2.14.0. Head: BUILD OK, output has only aws_xray_sdk and wrapt (plus copied source files); grep for botocore/jmespath/dateutil/six/urllib3 exit 1,…
S2 Same prune on a pyproject.toml without uv.lock, so the builder runs uv lock itself; this path also goes through _build_… ✅ pass No uv.lock, so the builder runs uv lock. Head: BUILD OK, LOCK_WRITTEN, no pruned names in output (grep exit 1), KEPT_OK. Base: botocore, jmespath, dateutil, six, urllib3 present in output (grep exit …
S3 requirements.txt builds must still resolve dependencies; the change must not add --no-deps there. ✅ pass requirements.txt with requests==2.32.3 on head: BUILD OK; requests, urllib3, idna, certifi and charset_normalizer all present, so the requirements.txt path still resolves transitive dependencies.
S4 Path dependency plus platform marker under --no-deps: a local path package's own dependency (six) must still be install… ✅ pass Path dependency mylib (needs six==1.16.0) plus click==8.1.7 on head: BUILD OK; mylib, six.py (six-1.16.0) and click present (KEPT_OK); colorama absent (grep exit 1); pth_count=0. --no-deps did not dr…
S5 Workspace member build with a workspace dependency and a prune: the member's workspace library and its dependency must … ✅ pass Workspace member wsapp depending on workspace lib wslib (six==1.16.0) and aws-xray-sdk, uv_prune [botocore]. Head: BUILD OK, LOCK_AT_ROOT, wslib, six.py, aws_xray_sdk, wrapt present (KEPT_OK); no bot…
S6 arm64 cross-build with extras and a direct prune under --no-deps: extra dependencies (PySocks from requests[socks]) mus… ✅ pass arm64 build of requests[socks]==2.32.3, PyYAML==6.0.3, boto3==1.35.0 with uv_prune [boto3] on head: BUILD OK; socks.py (PySocks extra), requests, urllib3, yaml present (KEPT_OK); native module is _ya…
S7 The repo's own python_uv unit tests and the prune integration tests, including the new test_workflow_prunes_transitive_… ✅ pass Head unit tests tests/unit/workflows/python_uv: 181 passed, 53 subtests passed, exit 0. Integration -k prune: 4 passed, none skipped, exit 0, including test_workflow_prunes_transitive_dependency_of_k…
Runner's notes in full
  • S1: Existing uv.lock, uv_prune [botocore], aws-xray-sdk==2.14.0. Head: BUILD OK, output has only aws_xray_sdk and wrapt (plus copied source files); grep for botocore/jmespath/dateutil/six/urllib3 exit 1, KEPT_OK. Base: build also succeeds but output contains botocore-1.44.7, jmespath, dateutil, six, urllib3 (grep exit 0), confirming the bug the PR fixes. Note: grep -c 'name = "botocore"' on uv.lock printed 4, not 1, because the pattern also matches dependency references; botocore is in the lock either way.
  • S2: No uv.lock, so the builder runs uv lock. Head: BUILD OK, LOCK_WRITTEN, no pruned names in output (grep exit 1), KEPT_OK. Base: botocore, jmespath, dateutil, six, urllib3 present in output (grep exit 0).
  • S4: Path dependency mylib (needs six==1.16.0) plus click==8.1.7 on head: BUILD OK; mylib, six.py (six-1.16.0) and click present (KEPT_OK); colorama absent (grep exit 1); pth_count=0. --no-deps did not drop the path package's own dependency.
  • S5: Workspace member wsapp depending on workspace lib wslib (six==1.16.0) and aws-xray-sdk, uv_prune [botocore]. Head: BUILD OK, LOCK_AT_ROOT, wslib, six.py, aws_xray_sdk, wrapt present (KEPT_OK); no botocore/jmespath/dateutil/urllib3 (grep exit 1). six is kept because wslib needs it. Base: KEPT_OK but botocore, jmespath, dateutil, urllib3 present (grep exit 0).
  • S6: arm64 build of requests[socks]==2.32.3, PyYAML==6.0.3, boto3==1.35.0 with uv_prune [boto3] on head: BUILD OK; socks.py (PySocks extra), requests, urllib3, yaml present (KEPT_OK); native module is _yaml.cpython-311-aarch64-linux-gnu.so; no boto3/botocore/s3transfer/jmespath (grep exit 1).
  • S7: Head unit tests tests/unit/workflows/python_uv: 181 passed, 53 subtests passed, exit 0. Integration -k prune: 4 passed, none skipped, exit 0, including test_workflow_prunes_transitive_dependency_of_kept_package in both TestPythonUvWorkflow_0 and TestPythonUvWorkflow_1_experimentalBuildPerformance. Logs 13/14 piped through tail; 15/16 are the unpiped reruns with true exit codes.

🤖 Automated hands-on test — not a review approval · model claude-opus-5.5 · Kiro kiro-cli 2.33.1 · build LambdaToolingHandsOn-NoDocker:c2ebc84d-05d2-4127-97bd-9693808fd63b · commit 7de59e1

History (1)
Commit Result When (UTC) Build
7de59e1 No problems observed 2026-11-20 16:49 LambdaToolingHandsOn-NoDocker:c2ebc84d-05d2-4127-97bd-9693808fd63b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant